import request from '@/utils/request';
import type { Result, PageResult } from '@/types/global';
import type { 
  ChargingData, 
  ChargingListParams,
  ChargingWithQrCodesVo,
  ChargingQrCodeVo
} from './types';

export { 
  ChargingData, 
  ChargingListParams, 
  ChargingWithQrCodesVo,
  ChargingQrCodeVo
};

const BASE_URL = '/api/charging';

// 获取充电桩列表
export function getChargingList(params: ChargingListParams) {
  return request.get<Result<PageResult<ChargingData>>>(`${BASE_URL}/list`, params);
}

// 新增充电桩
export function addCharging(data: Partial<ChargingData>) {
  return request.post<Result<void>>(`${BASE_URL}`, data);
}

// 更新充电桩
export function updateCharging(data: Partial<ChargingData>) {
  return request.put<Result<void>>(`${BASE_URL}`, data);
}

// 删除充电桩
export function deleteCharging(id: number) {
  return request.delete<Result<void>>(`${BASE_URL}/${id}`);
}

// 批量导入充电桩
export function importChargingPiles(data: Array<{
  code: string;
  name: string;
  socketCount: number;
  chargingGroupId?: number;
}>) {
  return request.post<Result<void>>(`${BASE_URL}/import`, data);
}

// 获取充电桩二维码
export function getChargingQrCodes(ids: string) {
  return request.get<Result<ChargingWithQrCodesVo[]>>(`${BASE_URL}/qrcodes`, { ids });
}

// 生成设备编号
export function generateDeviceCode() {
  return request.get<Result<string>>(`${BASE_URL}/generate-code`);
} 